package listener;

import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;

import com.qianfeng.lingshijia.R;

import fragment.SchoolMarketFragment;

/**
 * 优惠活动的点击事件
 */
public class OnPopupMenuClickListener implements View.OnClickListener{

    private SchoolMarketFragment fragment;

    public OnPopupMenuClickListener(SchoolMarketFragment fragment) {
        this.fragment = fragment;
    }

    @Override
    public void onClick(View v) {
        Log.e("onClick", "点击事件触发 ");
        PopupMenu popupMenu = new PopupMenu(fragment.getActivity(), fragment.getRgMarketType());
        popupMenu.inflate(R.menu.discount_action_menu);
        popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
            @Override
            public void onDismiss(PopupMenu menu) {
                fragment.getLvSchoolMarket().setAlpha(1);
            }
        });
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_all_market:
                        loadDataByString("orderBy=sales&universityNo=", item.getTitle().toString());
                        return true;
                    case R.id.menu_full_reduce:
                        loadDataByString("orderBy=manjian&universityNo=", item.getTitle().toString());
                        return true;
                    case R.id.menu_group_sell:
                        loadDataByString("orderBy=combination&universityNo=", item.getTitle().toString());
                        return true;
                }
                return false;
            }

            private void loadDataByString(String subString, String name) {
                fragment.setSubLoadDataString(subString);
                fragment.loadJson(fragment.getSubLoadDataString());
            }
        });
        fragment.getLvSchoolMarket().setAlpha(0.5f);
        popupMenu.show();
    }
}
